package nckd.wnqjt.tmc.tda.plugin.form;

import kd.bos.dataentity.serialization.SerializationUtils;
import kd.bos.entity.IFrameMessage;
import kd.bos.entity.report.FilterItemInfo;
import kd.bos.entity.report.ReportQueryParam;
import kd.bos.form.control.IFrame;
import kd.bos.report.plugin.AbstractReportFormPlugin;

import java.util.HashMap;
import java.util.Map;

public class BankLoanReminderReportPlugin extends AbstractReportFormPlugin {

    @Override
    public void initDefaultQueryParam(ReportQueryParam queryParam) {
        super.initDefaultQueryParam(queryParam);
    }

    @Override
    public void beforeQuery(ReportQueryParam param) {
        super.beforeQuery(param);
        if (param != null) {
            Map<String, Object> paramMap = transQueryParam(param);
            getPageCache().put("qFilter", SerializationUtils.toJsonString(paramMap));
        }
    }

    @Override
    public void afterQuery(ReportQueryParam queryParam) {
        super.afterQuery(queryParam);
        IFrameMessage message = new IFrameMessage();
        message.setType("reExtractData");
        IFrame qinganalysisap = (IFrame) this.getView().getControl("qinganalysisap");
        qinganalysisap.postMessage(message);
    }

    protected Map<String, Object> transQueryParam(ReportQueryParam param) {
        Map<String, Object> paramMap = new HashMap();
        for (FilterItemInfo filterItem : param.getFilter().getFilterItems()) {
            paramMap.put(filterItem.getPropName(), filterItem.getValue());
        }
        return paramMap;
    }
}
